<?php
$loader->requireOnce('includes/EwhExport/EwhReqExportQueueProc.class.php');

/**
 * Controler for valuate drug/material prices.
 * @package modules.dept_pharmacy.controllers
 * @author viethd
 * @version $Id$
 * @copyright 2009 LHV Company
 */
class C_EwhExportQueue extends Controller {
    private $logger ;
    private $reqExportQueueProc;
    function __construct($template_mod = "general") {
        parent::Controller();
        $this->logger = LoggerManager::getLogger('module.dept_pharmacy.controllers.C_EwhExportQueue');
        $this->template_mod = $template_mod;
        $this->view->path="pha_ewh_req_export_queue";
        $this->reqExportQueueProc = new EwhReqExportQueueProc($this);

    }

    /**
     * Display ewh request exprot Queue UI
     * @return html.
     */
    public function actionDisplayQueue() {
        $html = '';
        $html = $this->view->render('queue.html');
        return $html;
    }

    /**
     * Display ewh request exprot Queue UI
     * @return html.
     */
    public function actionDisplayAjax() {
        $this->logger->info('Start actionDisplayAjax');
        $result = array('error'=>array('code'=>CoreErrorCode::NORMAL,'mess'=>''),
        'result'=>array('pending'=>array(),'processed'=>array()));
        
        $filter1 = array('enum_destination'=>EnumerationConstant::PHA_REQ_DESINATION_EWH);
        $arrPendingReq = $this->reqExportQueueProc->listPendingRequests($filter1);
        $this->assign('arrPendingReq', $arrPendingReq);
        $result['result']['pending']['body'] = $this->view->render('req_pending_queue.html');
        $result['result']['pending']['total_table'] = '';
        $filter2 = array('enum_destination'=>EnumerationConstant::PHA_REQ_DESINATION_EWH,
        'limit'=>10);
        $arrProcessedReq = $this->reqExportQueueProc->listProcessedRequests($filter2);
        $this->assign('arrProcessedReq', $arrProcessedReq);
        $this->assign('rejectedStatus', EnumerationConstant::PHA_REQ_STATUS_REJECTED_KEY);
        $this->assign('acceptedStatus', EnumerationConstant::PHA_REQ_STATUS_ACCEPTED_KEY);
        $this->assign('arrProcessedReq', $arrProcessedReq);
        $result['result']['processed']['body'] = $this->view->render('req_processed_queue.html');
        $result['result']['processed']['total_table'] = '';        
        $this->logger->info('Finish actionDisplayAjax');
        return json_encode($result);
    }
    
    /**
     * Display ewh request exprot Queue UI
     * @return html.
     */
    public function actionDisplayProcessedRequestByFilterAjax() {
       $this->logger->info('Start actionDisplayAjax');
        $result = array('error'=>array('code'=>CoreErrorCode::NORMAL,'mess'=>''),
        'result'=>array('pending'=>array(),'processed'=>array()));
         $fDate = '';
        $tDate = '';
        if ($_POST['fromDateyyyy'] != '' && $_POST['fromDatemm'] && $_POST['fromDatedd']) {
            $fDate = sprintf("%04s-%02s-%02s 00:00:00", $_POST['fromDateyyyy']
            , $_POST['fromDatemm'], $_POST['fromDatedd']);
        }
        if ($_POST['toDateyyyy'] != '' && $_POST['toDatemm'] && $_POST['toDatedd']) {
             
            $tDate = sprintf("%04s-%02s-%02s 23:59:59", $_POST['toDateyyyy']
            , $_POST['toDatemm'], $_POST['toDatedd']);
        }

        //only get out the imticket not valuated yet
        $filter = array(
            'enum_destination'=>EnumerationConstant::PHA_REQ_DESINATION_EWH,
            "reqTicketCodeFilter"  =>  $_POST['reqTicketCodeFilter'],
            "fromDate"      =>  $fDate,
            "toDate"        =>  $tDate            
        );
        
        $arrProcessedReq = $this->reqExportQueueProc->listProcessedRequests($filter);
        $this->assign('arrProcessedReq', $arrProcessedReq);
        $this->assign('rejectedStatus', EnumerationConstant::PHA_REQ_STATUS_REJECTED_KEY);
        $this->assign('acceptedStatus', EnumerationConstant::PHA_REQ_STATUS_ACCEPTED_KEY);
        $this->assign('arrProcessedReq', $arrProcessedReq);
        $result['result']['processed']['body'] = $this->view->render('req_processed_queue.html');
        $result['result']['processed']['total_table'] = '';        
        $this->logger->info('Finish actionDisplayAjax');
        return json_encode($result);
    }
    
    /**
     * Display ewh request exprot Queue UI
     * @return html.
     */
    public function actionDisplayProcessedRequestByFilter() {
        $this->logger->info('Start actionDisplayProcessedRequestByFilter');
        $orders =   L10nHelper::getYMDorder();        
        $this->assign('datePart_0', $orders[0]);
        $this->assign('datePart_1', $orders[1]);
        $this->assign('datePart_2', $orders[2]);  
        $html = $this->view->render('ewh_search_processed_ticket.html');                
        $this->logger->info('Finish actionDisplayProcessedRequestByFilter');
        return $html;
    }


}
?>